/*
 */
package it.pride.primefacesShowcase.filters;

import java.util.Date;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

/**
 *
 * @author eluibon
 */
public class Like extends EmptyFilter implements Filter {

    private String value;

    public Like(String property, String value) {
        super(property) ;
        
        if ( !value.contains("*") ) {
            // if the string does not contain a * we append it, so that the search is interpreted ad a "startWith"
            this.value = value + "*";
        }
        else {
            this.value = value;
        }
    }

    @Override
    public Criterion getCriterion() {

        return ( value == null ) ? null : Restrictions.like(property, value.replace("*", "%"));
    }

    @Override
    public String toString() {
        return "Like{" + "value=" + value + '}';
    }
        
}
